﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Resources;
using EHTWebsite.Code;
using System.Text;
using System.IO;
using System.Net;
using System.Web.Security;
using EHTWebsiteProject.Code.Entity;
using EHTWebsiteProject.Code.BLL;

namespace EHTWebsiteProject.Administrator
{
    public partial class EHTModulUI : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    languageCode = Session[HangSo.LANGUAGE_CODE].ToString();
                    if (languageCode == "en-us")
                    {
                        IsVN = false;
                    }

                }
                catch (Exception ex)
                {
                }
                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
                LoadModul();
                if (IsVN == true)
                {
                    lbAdd_Edit.Text = HangSo.Add_VN;
                    plListModul.GroupingText = HangSo.ListModul;
                }
                else
                {
                    lbAdd_Edit.Text = HangSo.Add_Other;
                    plListModul.GroupingText = HangSo.ListModulOther;
                }
            }
        }

        /// <summary>
        /// Ham load ngon ngu
        /// </summary>
        /// <param name="ci"></param>
        public void LoadLanguage(CultureInfo ci)
        {

            lbHelp.Text = rm.GetString("lbHelp", ci);
            lbCancel.Text = rm.GetString("lbCancel",ci);
            lbSave.Text = rm.GetString("lbSave", ci);
        }

        public void LoadModul()
        {
            dtlListModul.DataSource = ModulProvider.GetAllModul(false, "", false);
            dtlListModul.DataBind();
        }

        protected void ImgSave_Click(object sender, ImageClickEventArgs e)
        {
            foreach (DataListItem rp in dtlListModul.Items)
            {
                CheckBox ckModul = (CheckBox)rp.FindControl("ckModul");
                Label lbID = (Label)rp.FindControl("lbID");
                if (ckModul.Checked == true)
                {
                    ModulProvider.UpdateChooseModul(Int32.Parse(lbID.Text), true);
                }
                else
                {
                    ModulProvider.UpdateChooseModul(Int32.Parse(lbID.Text), false);
                }
            }
            Response.Redirect("EHTModul.aspx");
        }

        protected void dtlListModul_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label lbChoose = (Label)e.Item.FindControl("lbChoose");
            CheckBox ckModul = (CheckBox)e.Item.FindControl("ckModul");
            if (lbChoose.Text == "True")
            {
                ckModul.Checked = true;
            }
        }
    }
}